;************************************************************************* ;*********************** LCDDigita THERMOMETER *************************** ;********************* LCD-ADC-LM35 Subroutine ************************** ;******************* NAME: Esmail bakhshzad mahmodi*********************** ;****************** Date = May 14, 2009 [Graphic] ********************** ;************************************************************************* ;Processor: Atmel AT89C52 Microcontroller (Compatible With MCS-51) ;1- P0.0 - P0.7 Connected to LCD output For Data Pins(D0 - D7) ;2- P1.0 - P1.7 Connected to ADC Input For Data Pins (DB0 - DB7) ;3- P2.0 Connected to LCD Output Data Pins ( RS ) ;4- P2.1 Connected to LCD Output Data Pins ( RW ) ;5- P2.2 Connected to LCD Output Data Pins ( E ) ;6- P3.7 Connected to ADC Output Pulse Read ( RD ) ;7- P3.6 Connected to ADC Output Pulse Write ( WR ) ;8- P3.5 Connected to ADC Input Pulse INTR ( INTR ) ;INTR ADC = Report Start-End Conversion ;Programmable Subroutine [THERMOMETER] Count_1 EQU 00 Count_2 EQU 16 LCD DATA P0 ;Define LCD Data Port 0 ADC_IN DATA P1 ;Define ADC Data Port 1 LCD_RS BIT P2.0 ;Define LCD Bit LCD_RS LCD_RW BIT P2.1 ;Define LCD Bit LCD_RW LCD_E BIT P2.2 ;Define LCD Bit LCD_E ADinter BIT P3.5 ;Define ADC Bit Inter AD_RW BIT P3.6 ;Define ADC Bit RW AD_RD BIT P3.7 ;Define ADC Bit RS ORG 0000h CLR A ;Clear Accumlator A MOV B,#00h ;Clear Accumlator B MOV P0,#00h ;Make Port P0 For Output MOV P1,#0FFh ;Make Port P1 For Input MOV P2,#11111000b ;Make Port P2 For Output MOV P3,#00111111b ;Make Port P3 For Output Input ADC(INTR) MOV R0,#00h ;Clear Bank0 sabot R0 MOV R1,#00h ;Clear Bank0 sabot R1 MOV R2,#00h ;Clear Bank0 sabot R2 MOV R3,#00h ;Clear Bank0 sabot R3 MOV R4,#00h ;Clear Bank0 sabot R4 MOV R5,#00h ;Clear Bank0 sabot R5 MOV R6,#00h ;Clear Bank0 sabot R6 MOV R7,#00h ;Clear Bank0 sabot R7 MOV A,#38h ;Init LCD lines2 5*7 Matrix LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#0Eh ;Display On Cursor LCD ( | ) LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give lcd Some Call Time Delay MOV A,#01h ;Command Clear LCD LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#06h ;Command cursor right (06h= shift) LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#80h ;Command Cursor to ( Line 1 ) pos1 LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay LCALL Disp_DATA ;Call subroutine [Disp_DATA] ;------------------------------------------------------------------------- ;-***************** ( Program Subroutine Thermometer) *******************- ;------------------------------------------------------------------------- ;Subroutine Read Code ADC [Thermometer] LCALL Disp_Thermo ;Call subroutine [Disp_Thermo] SETB AD_RD ;Low Pins P3.7 For Pulse Command (RD) LCALL Delay ;Give Lcd Some Call Time Delay START: CLR AD_RW ;Low Pins P3.5 For START Conversion (WR) LCALL Delay1 ;Give Lcd Some Call Time Delay1 SETB AD_RW ;High Pins P3.5 For START Conversion (WR) INTR: JNB ADinter,INTR ;Wait For End Of Conversion [INTR=1] CLR AD_RD ;Low Pins P3.7 For Pulse Command (RD) LCALL Delay1 ;Give Lcd Some Call Time Delay1 MOV A,ADC_IN ;Read PORT P1 Send to ( Accumlator A ) MOV R1,A ;Load Bank R1 For Save DIGIT Thermometer ACALL Convert ;Call Converting Subroutine ;------------------------------------------------------------------------- ;-***************** ( Display Data Thermometer ASCII ) ******************- ;------------------------------------------------------------------------- ;Subroutine Display Data Thermometer ASCII LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 MOV A,#0CCh ;Command Cursor Right(CC hex)Character-13 LCALL Command ;Call Command Subroutins Read MOV A,#0Ch ;Turn OFF Cursor (LINE 1) Display Data LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV A,R3 ;Load Accumlator A to Bank R3 LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] CALL Delay ;Give Lcd Some Call Time Delay MOV A,R1 ;Load Accumlator A to Bank R1 ( LSB ) LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#0DFH ;Display Letter ( ° ) LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#'C' ;Display Letter ( C ) LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 LJMP START ;Jump to START ;------------------------------------------------------------------------- ;-**************** ( Converting 8-bit Binary to ASCII ) *****************- ;------------------------------------------------------------------------- ;Subroutine Conversion 8-bit Binary to ASCII For Data Display Thermometer Convert:MOV B,#10 ;Send Accumlator B to 10 Binary MOV R1,A ;Send Bank R1 to Accumlator A DIV AB ;Divide By 10 Once More MOV R1,B ;Save Low Digit to Bank R1 MOV B,#10 ;Send Accumlator B to 10 Binary DIV AB ;Divide By 10 Once More ORL A,#30h ;Make it Code ASCII MOV R4,A ;Save MSD to Bank R4 MOV A,B ;Load Accumlator A to Accumlator B ORL A,#30h ;Make it Code 2nd Digit an ASCII MOV R3,A ;Load Accumlator A to Bank R3 Save MOV A,R1 ;Load Data Bank R1 to Accumlator A ORL A,#30h ;Make it Code 3rd Digit an ASCII MOV R1,A ;Save Code ASCII to Bank R1 Display RET ;Return ;------------------------------------------------------------------------- ;-***************** ( Display Data to ASCII [WELCOME] ) *****************- ;------------------------------------------------------------------------- ;Subroutine Display Data [WELCOME] Disp_DATA: MOV DPTR,#Ascii_Code ;Load Data Pointer [Ascii_Code] LOOPLCD:CLR A ;Clear Accumlator A MOVC A,@A+DPTR ;Move Data at A + DPTR Into [A] JZ EXITLCD ;Exit If Last ( Null ) Char LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 INC DPTR ;DPTR+1 Next Character MOV A,R1 ;Send Data Bank0 R1 to Accumlator A (RAM) MOV R0,#Count_2 ;Clear Bank0 sabot R0 INC A ;Accumlator A Add 1 ( A + 1 = A ) MOV R1,A ;Send Data Accumlator A to Bank0 R1 XRL A,R0 ;Comparator ( R0 = A ) , A = 16 JNZ LOOPLCD ;Jump If Not Equal to LOOPLCD LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Delay2 ;Give Lcd Some Call Time Delay2 MOV A,#01h ;Command Clear LCD LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time1 Delay MOV R1,#Count_1 ;Clear Bank0 sabot R1 SJMP LOOPLCD ;Jump to LOOPLCD EXITLCD:RET ;Return ;------------------------------------------------------------------------- ;-*************** ( Display Data to ASCII [Thermometer] ) ***************- ;------------------------------------------------------------------------- ;Subroutine Display Data [Thermometer] Disp_Thermo: MOV A,#06h ;Command cursor right (06h= shift) LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV A,#0C0h ;Command Cursor to ( Line 2 ) pos1 LCALL Command ;Call Command Subroutins Read LCALL Delay ;Give Lcd Some Call Time Delay MOV DPTR,#DATA_Therm ;Load Data Pointer [DATA_Therm] LOOP_TH:CLR A ;Clear Accumlator A MOVC A,@A+DPTR ;Move Data at A + DPTR Into [A] JZ EXIT_TH ;Exit If Last ( Null ) Char [EXIT_TH] LCALL Delay2 ;Give Lcd Some Call Time Delay2 LCALL Data_Disp ;Call Data_Disp Subroutins [Data_Disp] LCALL Delay2 ;Give Lcd Some Call Time Delay2 INC DPTR ;DPTR+1 Next Character MOV A,R1 ;Send Data Bank0 R1 to Accumlator A (RAM) MOV R0,#Count_2 ;Clear Bank0 sabot R0 INC A ;Accumlator A Add 1 ( A + 1 = A ) MOV R1,A ;Send Data Accumlator A to Bank0 R1 XRL A,R0 ;Comparator ( R0 = A ) , A = 16 JNZ LOOP_TH ;Jump If Not Equal to [EXIT_TH] MOV R1,#Count_1 ;Clear Bank0 sabot R1 SJMP LOOP_TH ;Jump to [LOOP_TH] EXIT_TH:RET ;Return ;------------------------------------------------------------------------- ;-********************** ( Send Command to LCD ) ************************- ;------------------------------------------------------------------------- ;Subroutine Send Command to LCD Command:MOV LCD,A ;Send Accumlator A to ( PORT P0 ) CLR LCD_RS ;Low Port P2.0 For Command ( RS=0 ) CLR LCD_RW ;Low Port P2.1 For Command Write ( RW=0 ) SETB LCD_E ;High Port P2.2 For Command Enable( E =1 ) ACALL Delay ;Give Lcd Some Call Time Delay CLR LCD_E ;Low Port P2.2 For Command Puls RET ;Return ;------------------------------------------------------------------------- ;-*********************** ( Write Data to LCD ) *************************- ;------------------------------------------------------------------------- ;Subroutine Write Data to LCD Data_Disp: MOV LCD,A ;Send Accumlator A to ( PORT P0 ) SETB LCD_RS ;High Port P2.0 For Command ( RS=1 ) CLR LCD_RW ;Low Port P2.1 For Command Write ( RW=0 ) SETB LCD_E ;High Port P2.2 For Command Enable( E =1 ) ACALL Delay ;Give Lcd Some Call Time Delay CLR LCD_E ;Low Port P2.2 For Command Puls RET ;Return ;------------------------------------------------------------------------- ;-******************* ( Give LCD Some Time 1 ms ) **********************- ;------------------------------------------------------------------------- ;Subroutine Delay (1ms) XTAL = 11.0592 Delay: MOV TMOD,#01 ;Make Timer0 Mode0 ( 16-Bit ) MOV TL0,#066h ;TL0= 66 hex , Low Byte Of Timer ( 1ms ) MOV TH0,#0FCh ;TH0= FC hex , High Byte Of Timer( 1ms ) SETB TR0 ;Start The Timer0 , Counter Again: JNB TF0,Again ;Stay Until Timer0 Rolls Over CLR TR0 ;Stop Timer0 CLR TF0 ;Clear Timer0 Flag0 RET ;Return Subroutins , ACALL ;------------------------------------------------------------------------- ;-******************* ( Give ADC Some Time 450 ns ) ********************- ;------------------------------------------------------------------------- ;Subroutine Delay1(450 ns) XTAL = 11.0592 Delay1: MOV TMOD,#01 ;Make Timer0 Mode0 ( 16-Bit ) MOV TL0,#0F9h ;TL0= F9 hex , Low Byte Of Timer(450 ns) MOV TH0,#0FFh ;TH0= FF hex , High Byte Of Timer(450 ns) SETB TR0 ;Start The Timer0 , Counter Again2: JNB TF0,Again2 ;Stay Until Timer0 Rolls Over CLR TR0 ;Stop Timer0 CLR TF0 ;Clear Timer0 Flag0 RET ;Return Subroutins , ACALL ;------------------------------------------------------------------------- ;-*************** ( Give Write Data Some Time 70ms ) ********************- ;------------------------------------------------------------------------- ;Subroutine Delay (70ms) XTAL = 11.0592 Delay2: MOV TMOD,#01 ;Make Timer0 Mode0 ( 16-Bit ) MOV TL0,#0FFh ;TL0= 0FF hex , Low Byte Of Timer ( 70ms ) MOV TH0,#01h ;TH0= 01 hex , High Byte Of Timer( 70ms ) SETB TR0 ;Start The Timer0 , Counter Again3: JNB TF0,Again3 ;Stay Until Timer0 Rolls Over CLR TR0 ;Stop Timer0 CLR TF0 ;Clear Timer0 Flag0 RET ;Return Subroutins , ACALL ;$$$$$$$$$$$$$$$$$$$$$$ ( Write Address Crossword ) $$$$$$$$$$$$$$$$$$$$$$ ;Subroutine Write Data Thermometer Ascii_Code: DB ' WELCOME ' DB ' DIGITAL SYSTEM ' DB ' THERMOMETER ' DB 'Esmail Bakhshzad' DB 'Date= May14,2009' DB 'Please Wait ... ' DB '>>>>>>>>>>>>>>>>' DB 0 DATA_Therm: DB 'Thermometer+?? C' DB 0 END